package org.bigjava;

import org.bigjava.bean.Posts;
import org.bigjava.bean.Topic;
import org.bigjava.user.service.impl.PostsServiceImpl;
import org.bigjava.user.service.impl.TopicServiceImpl;
import org.bigjava.user.service.impl.TypesServiceImpl;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import javax.servlet.ServletContext;
import java.util.List;

@SpringBootApplication
//@MapperScan(basePackages = {"org.bigjava.user.mapper", "org.bigjava.message.mapper"})
@MapperScan("org.bigjava.user.mapper")
public class QingYuApplication implements CommandLineRunner {
    @Autowired
    TypesServiceImpl typesService;
    @Autowired
    TopicServiceImpl topicService;
    @Autowired
    PostsServiceImpl postsService;
    @Autowired
    private ServletContext servletContext;

    public static void main(String[] args) {
        SpringApplication.run(QingYuApplication.class, args);
    }

    //首页默认处理
    @Override
    public void run(String... args) throws Exception {
        /*
        首页显示分类板块
         */
        //获取所有一级分类名
        List<String> indextypename = typesService.queryAllPrimaryClassification();
        //传入Application
        servletContext.setAttribute("onetypename", indextypename);

        /*
        首页显示热门动态板块
         */
        //获取首页热门推荐帖子
        List<Posts> hotposts = postsService.postsHot();
        //传入Application
        servletContext.setAttribute("hotposts", hotposts);


        /*
        首页默认显示热门话题
         */
        //获取第一页热门话题
        List<Topic> hotTopic = topicService.indexHotTopic(1);
        //传入Application
        servletContext.setAttribute("indexhotTopic", hotTopic);


    }
}
